import axios from 'axios'

const API_PREFIX = import.meta?.env?.VITE_API_PREFIX || ''

export async function fetchSettingsOverview() {
  if (API_PREFIX) {
    const res = await axios.get(`${API_PREFIX}/settings/overview`)
    return res.data
  }
  return {
    account: { phoneMasked: '138****8888', hasPassword: true, thirdBindings: { wechat: false, alipay: true } },
    cacheSize: '66M'
  }
}

export async function requestSmsCode(phone) {
  if (API_PREFIX) {
    const res = await axios.post(`${API_PREFIX}/settings/sms`, { phone })
    return res.data
  }
  return new Promise(resolve => setTimeout(() => resolve({ success: true, code: '123456' }), 500))
}

export async function changePhone({ phone, code }) {
  if (API_PREFIX) {
    const res = await axios.post(`${API_PREFIX}/settings/change-phone`, { phone, code })
    return res.data
  }
  return new Promise(resolve => setTimeout(() => resolve({ success: true }), 600))
}

export default {
  fetchSettingsOverview,
  requestSmsCode,
  changePhone
}


